/**
 * @author 小泽玛丽罗
 */
	
var tmpl_notice='<div class="umh5 umw3 ">'
 	
 				+'<div  class="ub umh5 umw3 unn b-gra c-wh uc-t1 " style="border:1px solid #c5c5c5;3px 3px 6px rgba(180, 178, 178, 0.76) ">'
						
							+'<div class="umw3 umh5 umar-a"><img style="width:4em;height:4em" src="css/image/.png"/></div>'
								+'<div class="ub ub-f1 ub-ver" style="margin-left:0.4em">'
							
							+'<div class="ub umh5 uc-b ub-ac lis ">'
 									+'<div class="ub ub-f1" style="font-size:1em;font-weight:bold;">系统通知</div>'
									
 											+'<div class="ub-f1 tx-r" style="padding:0.2em;float:right;font-size:1.2em;color:rgb(170,170,170)">${ctime}</div>'
				
							+'</div>'
							 
							+'<div class="t-gra" style="font-size:1em;padding-bottom:0.5em">${content}</div>'
						
							
		
					+'</div>'
       			+'</div>  ' 
	
	
 			+'</div>';
				 +'</div>';
var tmpl_add='<div id="Friend" name="Friend" onclick="add(this)" class="ub umh5  unn c-wh tx-c ub-ver" style="border:1px solid #c5c5c5;background-color:#ebebeb; ">'
		+'<div ontouchstart="zy_touch('+'btn-act'+')" class="btn ulev1 uinn5 uc-a t-bla">更多</div>'
 +'</div>';
var sysNoticeUrl='http://www.diaoyumi.ourstu.com/api/notify/getSystemNotifyList';
window.localStorage.setItem("noticeOffset",0);
function loadSystemNotice(){
	uexWindow.toast(1,5,"加载中",0);
	var httpID=7462897;
	uexXmlHttpMgr.onData=function (inOpCode,inStatus,inResult){
		if(inStatus==1){
			var json=eval("("+inResult+")");
			if(json["success"]){
				window.localStorage.setItem("noticeData",JSON.stringify(json));
				noticeDataAppend();
			}else{
				uexWindow.toast(1,5,json["message"],1000);
			}
		}
	}
	uexXmlHttpMgr.open(httpID,'post',sysNoticeUrl,3000);
	uexXmlHttpMgr.setPostData(httpID,'0',"session_id",window.localStorage["session_id"]);
	if(window.localStorage["noticeOffset"]!=0){
		uexXmlHttpMgr.setPostData(httpID,'0',"offset",window.localStorage["noticeOffset"]);
	}
	uexXmlHttpMgr.send(httpID);
}
function add(obj){
	obj.parentNode.removeChild(obj);
	loadSystemNotice();
}

function noticeDataAppend(){
	var json=window.localStorage["noticeData"];
	json=eval("("+json+")");
	var len=zy_tmpl_count(json["list"]);
	if(len!=0){
		window.localStorage.setItem("noticeOffset",len+parseInt(window.localStorage["noticeOffset"]));
		for(var i=0;i<len;i++){
			var obj=json["list"][i];
			obj["ctime"]=addFriendlyTime2(obj["ctime"]);
			var div=document.createElement("DIV");
			var notice=zy_tmpl_s(tmpl_notice,obj,zy_tmpl_count(obj));
			div.innerHTML=notice;
			document.body.appendChild(div);
		}
		var div=document.createElement("DIV");
		var add=zy_tmpl_s(tmpl_add,json,zy_tmpl_count(json));
		div.innerHTML=add;
		document.body.appendChild(div);
		uexWindow.closeToast();
	}else{
		uexWindow.toast(1,5,"没有更多了",1000);
	}
}

 //下拉刷新部分的函数
 
 function set_bounce(){
	uexWindow.setBounce("1");
    setUpstyle("最后一次刷新时间:xxxx");
    uexWindow.showBounceView("0","rgba(142,201,96,30)","1");
    uexWindow.showBounceView("1","rgba(142,201,96,30)","0");
    uexWindow.notifyBounceEvent('0','1');
    uexWindow.onBounceStateChange = function(type,state){
      if(type == '0' && state == "2"){
	  	alert("1");
		window.localStorage.setItem("noticeOffset",0);
		alert("2");
		loadData();
		 alert("3");
      } 
	  //alert("2");
	 
    }
}
function addFriendlyTime2(timestampInPage){
	var timestampNow = Math.round(new Date().getTime()/1000);
   var dif = timestampNow-timestampInPage;
   var outPut ="";

   if (dif<=15) outPut ="刚才";
   else if(dif<60) outPut=dif+"秒前";
   else if(dif<3600) outPut=Math.round(dif/60)+"分钟前";
   else if(dif<86400) outPut=Math.round(dif/3600)+"小时前";
   else {
       var date = new Date(timestampInPage*1000);
       var hours = date.getHours();
       var minutes =date.getMinutes();
       if(hours<10) hours = "0"+hours;
       if(minutes<10) minutes="0"+minutes;

       outPut = date.getMonth()+1+"-"+(date.getDate()+1)+" "+hours+":"+minutes;
   }
   return outPut;
}
function refreshClear(){
	alert("4");
		var divAll=$("body>div");
		alert("5");
		divAll.remove();
		alert("6");
	}
	
	 function loadData(){
    //uexWindow.toast(1,5,"loading....",2000);
    //2秒后，恢复弹动初始状态
	refreshClear();
	alert("7");
	loadSystemNotice();
	alert("8");
    setTimeout(function(){uexWindow.resetBounceView('0');},1500);
  }
   function setUpstyle(ltext){
    var json_p = '{"imagePath":"res://refresh_upicon.png","textColor":"#FFF","levelText":"'+"最后一次刷新时间"+window.localStorage["refreshTimeWeibo"]+'","pullToReloadText":"下拉可以刷新","releaseToReloadText":"松开即可刷新","loadingText":"正在刷新中..."}';
    uexWindow.setBounceParams('0',json_p);
	alert("9");
  }		